package com.sunni.listener.util;

import org.springframework.context.ApplicationContext;

import javax.servlet.ServletContext;

public class GetApplicationContextUtil {

    /**
     * 获取spring容器（从ServletContext作用域中）
     * @param servletContext 根据传入的ServletContext作用域
     * @return spring容器
     */
    public static ApplicationContext getApplicationContext(ServletContext servletContext){
        return (ApplicationContext) servletContext.getAttribute("app"); //这里的"app", 必须和Listener里setAttr的("app")一样
    }
}
